package com.esd.util;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;

import org.eclipse.jetty.util.log.Log;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class MkFile {
	private static  Logger log = LoggerFactory.getLogger(MkFile.class);
	
	/**
	 * 建文件夹
	 * @param dir
	 * @return
	 */
	public static boolean mkdir (String dir){
		File file = new File(dir);
		if  (!file .exists()  && !file .isDirectory())      
		{       
		    System.out.println("//不存在");  
		    file .mkdir();    
		} else   
		{  
		    System.out.println("//目录存在");  
		}
		return true;
	}
	
	public static boolean writeFile(byte[] b,String dir){
		
		  File f = new File(dir);
		  if(!f.exists()){
			  try {
				f.createNewFile();
			} catch (IOException e) {
				log.error("IOException", e);
			}
		  }else{
			  f.delete();
			  try {
				f.createNewFile();
			} catch (IOException e) {
				log.error("IOException", e);
			}
		  }
		  boolean flag=false;  
		  FileOutputStream o=null;
		  try {  
			  o = new FileOutputStream(f);  
		      o.write(b);  
		      o.close();  
		      flag=true;  
		  } catch (Exception e) {  
			  log.error("Exception", e);
		  }
		  return flag;  
	 }
}
